<script type="text/javascript" src="<?=base_url()?>resource/plugins/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
    .selected
    {
/*        background:#0099ff;*/
/*        color:#0099ff;*/
    }
</style>
<!--top结束-->
<div class="mian">
    <div class="mian1">
        <div class="mian2">
            <!--left start-->
            <?php $this->load->view('defaults/common/left'); ?>
            <!--left end-->

            <!--right start-->
            <div class="right">
                <!--breadcrumb start-->
                <div class="righta"><?= $this->breadcrumb->generateHTML(); ?> </div>
                <!--breadcrumb end-->

                <!-- contents start -->
                <div id="contents">
                    <div id="ct_search">
                        <form action="<?= $status_url ?>"  >
                            <table id="search_tb">
                                <tr>
                                    <td>
                                        搜索： <input type="text" name="sku" id="sku" size="20" placeholder="sku 或 维修单号">&nbsp;&nbsp;
                                        仓库：<select  name="whs"  placeholder="whs">
                                            <option value ="">All</option>
                                           <?php foreach($whs as $oneWhs){?>
                                                  <option value ="<?=$oneWhs['whs_code']?>"><?='('.$oneWhs['whs_code'].')'.$oneWhs['whs_name']?></option>  
                                                                        <?php }?>
                                        </select>
                                        时间：
                                        <input type="text" name="startTime" value="<?=$startTime?>" onfocus="WdatePicker({lang:'en'})" class="Wdate" />&nbsp; -
                                        <input type="text" name="endTime" value="<?=$endTime?>" onfocus="WdatePicker({lang:'en'})" class="Wdate" />&nbsp;&nbsp;
                                        <br/>
                                        状态：<select  id="status_select_id"  placeholder="status"  onchange="status_select()">
                                           <?php foreach($status as $status_k=> $status_v){?>
                                                  <option value ="<?=$status_k?>"><?=$status_v?></option>  
                                                                        <?php }?>
                                                  <option value ="ALL">全部</option>  
                                        </select>
                                        <input type="submit" value=" <?= lang('wms_ss') ?>  "  style="margin-left: 20px;">
                                        <?php if(1==$list_status):?>
                                       <input type="button" onclick="selectedSubmit(7)" style="margin-left: 20px;" value="深圳已到货">
                                        <input type="button" onclick="selectedSubmit(6)" style="margin-left: 20px;" value="延迟到货">
                                        <input type="button" onclick="selectedSubmit(11)" style="margin-left: 20px;" value="无法采购">
                                        <input type="button" onclick="selectedSubmit(10)" style="margin-left: 20px;" value="已取消">
                                        <?php elseif(in_array($list_status,array(5,6))):?>
                                         <input type="button" onclick="selectedSubmit(7)" style="margin-left: 20px;" value="深圳已到货">
                                        <input type="button" onclick="selectedSubmit(11)" style="margin-left: 20px;" value="无法采购">
                                        <input type="button" onclick="selectedSubmit(10)" style="margin-left: 20px;" value="已取消">
                                        <?php elseif(7==$list_status):?>
                                      <input type="button" onclick="selectedSubmit(8)" style="margin-left: 20px;" value="深圳已发货">
                                        <?php elseif(8==$list_status):?>
                                        <input type="button" onclick="selectedSubmit(9)" style="margin-left: 20px;" value="海外入库">
                                        <?php endif;?>
                                    </td>
                                </tr>
                            </table>
                        </form>
                    </div>
                    <div class="ct_content">
                        <table class="tbwd800">
                            <tr>
                                <th>申请采购时间</th>
                                <th>仓库代码</th>
                                <th>物料号</th>
                                <th>物料名称</th>
                                <th>需求数量</th>
                                <th>来源号</th>
                                <th>客户类型</th>
                                <th>报价</th>
                                <th>成本</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            <?php
                            $urlParam = @http_build_query($this->input->get());
                            foreach ($accessory_purchase_list as $key => $row)
                            {
                                ?>
                                <tr class="parent" id="row_<?= $key ?>"><td colspan="3">仓库-物料：<?= $row['whs_code'] ?>--<?= $row['sku'] ?></td>
                                    <td colspan="7">(<?= count($row['child']) ?>)&nbsp;Item→<?= array_sum(array_column($row['child'], "quantity")) ?>&nbsp;total&nbsp;&nbsp;↓</td>
                                    <td colspan="1" class='check_td'><input type='checkbox'   class='checkall' id="<?= $key ?>" /></td>
                                </tr>

                                <?php
                                foreach ($row['child'] as $k => $r)
                                {
                                    ?>
                                    <tr  class="child_row_<?= $key ?>" align="left" class="moves">
                                        <td><?= $r['add_date'] ?></td>
                                        <td><?= $r['whs_code'] ?></td>
                                        <td><?= $r['sku']; ?></td>
                                        <td><?= $r['title'] ?></td>
                                        <td><?= $r['quantity'] ?></td>
                                        <td><?= $r['order_id'].'-'.$r['pid'].'-'.$r['part_id'] ?></td>
                                        <td><?= $r[''] ?></td>  
                                        <td><?= $r['purchase_price'] ?></td>  
                                        <td><?= $r['accessory_cost'] ?></td>
                                        <td><?= $status[$r['status']] ?></td>
                                        <td><input type='checkbox'  name='checkid<?= $key ?>' class="checkid" value='<?= $r['id'] ?>' /></td>
                                    </tr>
                                <?php } ?>
                            <?php } ?>
                            <tr align="center">
                                <td colspan="11"><?= $pageShow ?></td>
                            </tr>
                        </table>
                    </div>
                </div>
                <!-- contents end -->
            </div>
            <!--right end-->
            <div class="clear"></div>
        </div>
    </div>
</div>

<script type="text/javascript">
    //折叠
    $(function () {
 
        //展开与折叠表格
        $("tr.parent").css("cursor","pointer")//添加一个样式
        .click(function () {//得到所在的那行表格并添加单击事件
            $(this).toggleClass("selected")//添加/删除高亮
            .siblings(".child_" + this.id).toggle(); //隐藏/显示所谓的子行
            $(this).siblings(".checkid").prop('checked', true); //隐藏/显示所谓的子行
        }).click();
    });
    $('.check_td').bind("click",function(event){
        event.stopPropagation();    //  阻止事件冒泡
    });
    $(".checkall").click(
    function(){
        if(this.checked){
            $("input[name='checkid"+this.id+"']").prop('checked', true)
        }else{
            $("input[name='checkid"+this.id+"']").prop('checked', false)
        }
    } 
);
    $("#status_select_id").val("<?= $list_status ?>");
function status_select(){
    var status = $("#status_select_id").val();
        window.location.href=('<?= blang_url("wms/PurchaseList/show") ?>/'+status+'?<?= $urlParam ?>');
}
    function selectedSubmit(status){
        var r=confirm("<?= lang('wms_tips_tsqrrk'); ?>");
        var ids=new Array()
        if(r){
            $(".checkid:checkbox:checked").each(function(){
                ids.push($(this).val());
            });
        }
        if(ids.length<1){
            alert('<?= lang('wms_tips_xzjl'); ?>');
            return false ;
        }
        //        var idsjson=JSON.stringify(ids);
        var idsStr =ids.join();
        window.location.href=('<?= blang_url("wms/PurchaseList/need_batch") ?>/'+status+'?ids='+idsStr+'&<?= $urlParam ?>');
        
    }  
</script>
